package com.jandan.ui.client.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import java.util.Map.Entry;

import com.gwtext.client.widgets.form.Form;

public class ClientUtil {
	public static final String LESSON_STUDY_ID = "lesson_study";
	
	//study style
	public static final int STUDY_NEW_WORD = 0;
	public static final int REVIEW_OLD_WORD = 1;
	public static final int STUDY_STRANGE_WORD = 2;
	public static final int LESSON_NEW_WORD = 0;
	public static final int REVIEW_WORD = 1;
	public static final int REMEMBER = 0;
	public static final int CHOOSE_ANSWER = 1;
	public static final int FIRST_LEARNED = 1;
	public static final int UNKNOW = 1;
	public static final int KNOW = 2;
	public static final int MASTER = 3;
	public static final String[] ANSWERS = {"A","B","C","D","E","F","G"};
	public static final String[] DEGREES = {"","陌生","认识","掌握"};
	public static final int COMMON_LESSON = 1;
	public static final int STRANGE_WORK_BOOK_LESSON = 2;
	public static final int STRANGE_WORD_GROUP_SIZE = 50;	//每个小词库分组的大小
	public static final long STRANGE_LESSON_ID = 999999999;

	public static final int STRANGE_WORDLIB_ID = 99999;

	public static final int FIRST_PAGE_INDEX = 0;

	public static final int ACCOUNT_PAGE_LIMIT = 5;

	public static final int WORDLIB_PAGE_LIMIT = 5;

	public static final int ARITCLE_PAGE_LIMIT = 5;
	
	public static int DELETE_LESSON = 0;

	public static int ANSWER_COUNT = 7;
	
	public static final String[] BLOG_CATEGORIES = new String[]{"煎蛋热文","系统更新","杂谈","资源","帮助"};
	
	public static final String[] autorities = new String[]{"注册用户","管理员","超级管理员"};

	public static final int REGISTER = 1;
	public static final int ADMINISTRATOR = 2;
	public static final int SUPER_ADMINISTRATOR = 3;

	public static final long STANDARD_WORDLIB_ID = 0;

	public static Object[][] mapToStringArray(TreeMap<Long, String> map) {
		// TODO Auto-generated method stub
		String[][] datas =  new String[map.size()][];
		Set<Entry<Long, String>> set = map.entrySet();
		Iterator<Entry<Long, String>> it = set.iterator();
		
		int i = 0;
		String[] strs = null;
		Entry<Long,String> entry = null;
		while(it.hasNext()){
			strs = new String[2];
			entry = it.next();
			strs[0] = entry.getKey().toString();
			strs[1] = entry.getValue();
			
			datas[i++] = strs;
		}
		
		return datas;
	}
	
	public static Map<String,String> getFormDataAsMap(Form form){
		Map<String,String> formData = new HashMap<String,String>();
		String formValues = form.getValues();
		
		String[] nameValuePairs = formValues.split("&");
		String[] oneItem = null;
		int length = nameValuePairs.length;
		for(int i = 0;i < length;i++){
			oneItem = nameValuePairs[i].split("=");
			formData.put(oneItem[0], oneItem[1]);
		}
		
		return formData;
	}


}
